var $ = require('../../lib/jquery');
var util = require('./common/util');
var nav = require('./common/nav');
require('./common/doubleDate2.0');
var _header = require('./common/header');
var template = require('../tpl/template');
var minHeight = require('./common/minHeight');
minHeight.init();
var _nav = new nav();
var header = new _header();
var formIsNeed = {
    phonenumber: true,
    recorddate: true,
    workunit: true,
    contactorname: true,
    contactorphone: true,
};
var uploadParmas = {
    "memberBase": {
        curaddress: '', //否 现在详细地址
        hometown: '', //否 户籍
        phonenumber: '', //是 自己 的手机号
        householdtype: '1', //是 常住类型
        rhbloodtype: '5', //是 血型
        // creator:'',//否   建档人 未找到dome
        referraldoctor: '', //是 签约医生 上个页面带过来的
        recorddate: '', // 是 建档日期 
        workunit: '', // 是 工作单位
        contactorname: '', // 是 联系人姓名
        contactorphone: '', // 是 联系人电话
        professiontype: '1', //  是 职业 
        addrstreetcode: '', // 否 乡镇（街道）名称
        addrcommitteecode: '', // 否 村（居）委会名称
        ethnictype: '1', // 是 民族
        educationlevel: '2', //是 文化程度
        maritalstatus: '1', //是 婚姻状况
        paytype: '1', // 医疗费用支付方式 是 （医保类型）
        //遗传病
        fhfather: "2", //shi 
        fhmother: "2", //shi 
        fhbrother: "2", //shi 
        fhchildren: "2", //shi 
        fhfatherdes: "", //否
        fhmotherdes: "", //否
        fhbrotherdes: "", //否
        fhchildrendes: "", //否

        //药物过敏史
        allergyhistory: "1", //shi 
        allergydescription: "",

        //暴露史
        exposurehistory: '2',

        //残疾情况
        disability: '2', //无 
        disabilitydescription: '', //fou

        //吸烟室
        smsmoking: '2', //1抽
        smstart: '', //吸烟开始时间 否
        smend: '', //吸烟结束时间 否
        smamount: '', //吸烟量 否

        //喝酒是
        dkdrinking: '2', //是否喝酒 1是
        dktype: '', //喝酒种类 否
        dkamount: '', //喝酒量 否
        dkrate: '', //喝酒频率 否
        dkend: '', //戒酒时间 否

        //体育锻炼
        exexercise: '2', //是否锻炼 1是
        excycle: '', //..锻炼情况 否
        extime: '', //每次锻炼时间 否
        extype: '', //锻炼类型 否

        //饮食习惯
        fhtype: '1', //饮食类型  是
        fhamount: '', //饮食量 否

        //睡眠情况
        sltime: "2", //睡眠量 否
        slsituation: "2", //睡眠障碍 否
        sldescription: '', // 描述 否
        leairexhaust: '',
        lefuel: '',
        lewater: '',
        lewc: '',
        lelivestock: '',
    },
    // 身高体重表 type1身高2体重3腰围4臀围5收缩压6舒张压

    "indicatorList": [],
    "problemList": [],
    //既往史 
    'historyList': [{
            "historytype": "1", //既往史类型 ，1疾病史2手术3外伤4输血
            "optiontype": "2", //选项类型 2无，1有
            "description": "", // 疾病史描述
            "occurrencetime": '', //其他的发生时间
        },
        {
            "historytype": "2", //既往史类型 ，1疾病史2手术3外伤4输血
            "optiontype": "2", //选项类型 2无，1有
            "description": "", // 疾病史描述
            "occurrencetime": '', //其他的发生时间
        },
        {
            "historytype": "3", //既往史类型 ，1疾病史2手术3外伤4输血
            "optiontype": "2", //选项类型 2无，1有
            "description": "", // 疾病史描述
            "occurrencetime": '', //其他的发生时间
        },
        {
            "historytype": "4", //既往史类型 ，1疾病史2手术3外伤4输血
            "optiontype": "2", //选项类型 2无，1有
            "description": "", // 疾病史描述
            "occurrencetime": '', //其他的发生时间
        },
    ],





}

var createDA = {
    init: function (data) {
        this.bindevent();
        this.getUserInfo();
    },
    getUserInfo: function () {
        util.fetch('api/medical/dock/queryArchives').then(function (res) {
            if (res.data.code == '101' || res.data.code == '109') {} else {
                $('.tit').hide();
                var data = JSON.parse(res.data.result);
                $('.js_curaddress').val(data.memberBase.curaddress);
                uploadParmas.memberBase.curaddress = data.memberBase.curaddress;
                $('.js_addrstreetcode').val(data.memberBase.addrstreetcode);
                uploadParmas.memberBase.addrstreetcode = data.memberBase.addrstreetcode;
                $('.js_addrcommitteecode').val(data.memberBase.addrcommitteecode);
                uploadParmas.memberBase.addrcommitteecode = data.memberBase.addrcommitteecode;
                $('.js_curaddress').val(data.memberBase.curaddress);
                uploadParmas.memberBase.curaddress = data.memberBase.curaddress;
                if (data.memberBase.householdtype != 1) {
                    $(".js_householdtype  .yi").removeClass("cb");
                    $(".js_householdtype  .er").addClass("cb");
                }

                uploadParmas.memberBase.householdtype = data.memberBase.householdtype;
                $('.js_hometown').val(data.memberBase.hometown);
                uploadParmas.memberBase.hometown = data.memberBase.hometown;
                $('.js_recorddate').val(data.memberBase.recorddate);
                uploadParmas.memberBase.recorddate = data.memberBase.recorddate || '';
                $('.js_phonenumber').val(data.memberBase.phonenumber);
                uploadParmas.memberBase.phonenumber = data.memberBase.phonenumber;
                if (data.memberBase.ethnictype != 1) {
                    $(".js_ethnictype  .yi").removeClass("cb");
                    $(".js_ethnictype  .er").addClass("cb")
                }
                uploadParmas.memberBase.ethnictype = data.memberBase.ethnictype;
                $('.js_rhbloodtype .san').removeClass('cb');
                $('.js_rhbloodtype .san').eq(data.memberBase.rhbloodtype - 1).addClass('cb');
                uploadParmas.memberBase.rhbloodtype = data.memberBase.rhbloodtype
                $('.js_workunit').val(data.memberBase.workunit);
                uploadParmas.memberBase.workunit = data.memberBase.workunit;
                $('.js_contactorname').val(data.memberBase.contactorname);
                uploadParmas.memberBase.contactorname = data.memberBase.contactorname;
                $('.js_contactorphone').val(data.memberBase.contactorphone);
                uploadParmas.memberBase.contactorphone = data.memberBase.contactorphone;
                $('.js_educationlevel .circle').removeClass('cb');
                $('.js_educationlevel .circle').eq(data.memberBase.educationlevel - 1).addClass('cb');
                uploadParmas.memberBase.educationlevel = data.memberBase.educationlevel;
                $('.js_professiontype .circle').removeClass('cb');
                $('.js_professiontype .circle').eq(data.memberBase.professiontype - 1).addClass('cb');
                uploadParmas.memberBase.professiontype = data.memberBase.professiontype
                $('.js_maritalstatus .circle').removeClass('cb');
                $('.js_maritalstatus .circle').eq(data.memberBase.maritalstatus - 1).addClass('cb');
                uploadParmas.memberBase.maritalstatus = data.memberBase.maritalstatus
                $('.js_paytype .check').removeClass('checkG');
                uploadParmas.memberBase.paytype = data.memberBase.paytype;
                uploadParmas.memberBase.leairexhaust=data.memberBase.leairexhaust;

                $('.js_leairexhaust .js_live').find('.bb').removeClass('colorCircle');
                $('.js_leairexhaust .js_live').eq(data.memberBase.leairexhaust-1).find('.bb').addClass('colorCircle');
                uploadParmas.memberBase.lefuel =data.memberBase.lefuel;
                $('.js_lefuel .js_live').find('.bb').removeClass('colorCircle');
                $('.js_lefuel .js_live').eq(data.memberBase.js_lefuel-1).find('.bb').addClass('colorCircle');
                
                uploadParmas.memberBase.lewater =data.memberBase.lewater;
                $('.js_lewater .js_live').find('.bb').removeClass('colorCircle');
                $('.js_lewater .js_live').eq(data.memberBase.lewater-1).find('.bb').addClass('colorCircle');

                uploadParmas.memberBase.lewc =data.memberBase.lewc;
                $('.js_lewc .js_live').find('.bb').removeClass('colorCircle');
                $('.js_lewc .js_live').eq(data.memberBase.lewc-1).find('.bb').addClass('colorCircle');
                uploadParmas.memberBase.lelivestock =data.memberBase.lelivestock;
                $('.js_lelivestock .js_live').find('.bb').removeClass('colorCircle');
                $('.js_lelivestock .js_live').eq(data.memberBase.lelivestock-1).find('.bb').addClass('colorCircle');

                var paytype = data.memberBase.paytype.split(',');
                for (let i = 0; i < paytype.length; i++) {
                    $('.js_paytype .check').eq(Number(paytype[i]) - 1).addClass('checkG');
                }

                //身高
                for (let j = 0; j < 6; j++) {
                    $('.js_indicatorList').eq(j).val(data.indicatorList[j].indicator);
                    uploadParmas.indicatorList.push({
                        "indicator": data.indicatorList[j].indicator,
                        "type": data.indicatorList[j].type
                    })
                }
                //既往史js_historyDisease
                var historym = 5;
                uploadParmas.historyList = [];
                for (let t = 0; t < 4; t++) {
                    historym -= 1;
                    uploadParmas.historyList.push({
                        "historytype": data.historyList[data.historyList.length - historym].historytype,
                        // "historytype":t+1,
                        "optiontype": data.historyList[data.historyList.length - historym].optiontype,
                        "description": data.historyList[data.historyList.length - historym].description,
                        "occurrencetime": data.historyList[data.historyList.length - historym].occurrencetime,
                    })

                    if (data.historyList[data.historyList.length - historym].optiontype == 1) {
                        $('.js_historyDisease').eq(t).find(".circle").eq(0).removeClass('cb');
                        $('.js_historyDisease').eq(t).find(".circle").eq(1).addClass('cb');
                    }
                    if (data.historyList[data.historyList.length - historym].historytype == 1) {
                        var arr = data.historyList[data.historyList.length - historym].description.split(',');
                        for (var n = 0; i < arr.length; n++) {
                            $('.js_historyDisease').eq(0).find('.duoxuan .js_kuang').eq(Number(arr[n]) - 2).addClass('checkG');
                        }

                    } else {
                        $('.js_historyDisease').eq(t).find('.miaosu input').eq(0).val(data.historyList[data.historyList.length - historym].description);
                        $('.js_historyDisease').eq(t).find('.miaosu input').eq(1).val(data.historyList[data.historyList.length - historym].occurrencetime);

                    }


                }

                // console.log( uploadParmas.historyList)
                //遗传病史

                if (data.memberBase.fhfather != 2) {
                    $('.js_fhfather .circle').eq(1).addClass('cb');
                    $('.js_fhfather .circle').eq(0).removeClass('cb');
                    let arr = data.memberBase.fhfatherdes.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        $('.js_fhfatherdes .js_kuang').eq(Number(arr[i]) - 2).addClass('checkG')
                    }
                }
                uploadParmas.memberBase.fhfather = data.memberBase.fhfather;

                uploadParmas.memberBase.fhfatherdes = data.memberBase.fhfatherdes;
                if (data.memberBase.fhmother != 2) {
                    $('.js_fhmother .circle').eq(1).addClass('cb');
                    $('.js_fhmother .circle').eq(0).removeClass('cb');
                    let arr = data.memberBase.fhmotherdes.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        $('.js_fhmotherdes .js_kuang').eq(Number(arr[i]) - 2).addClass('checkG')
                    }
                }
                uploadParmas.memberBase.fhmother = data.memberBase.fhmother;
                uploadParmas.memberBase.fhmotherdes = data.memberBase.fhmotherdes;

                if (data.memberBase.fhbrother != 2) {
                    $('.js_fhbrother .circle').eq(1).addClass('cb');
                    $('.js_fhbrother .circle').eq(0).removeClass('cb');
                    let arr = data.memberBase.fhbrotherdes.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        $('.js_fhbrotherdes .js_kuang').eq(Number(arr[i]) - 2).addClass('checkG')
                    }
                }
                uploadParmas.memberBase.fhbrother = data.memberBase.fhbrother;
                uploadParmas.memberBase.fhbrotherdes = data.memberBase.fhbrotherdes;

                if (data.memberBase.fhchildren != 2) {
                    $('.js_fhchildren .circle').eq(1).addClass('cb');
                    $('.js_fhchildren .circle').eq(0).removeClass('cb');
                    let arr = data.memberBase.fhchildrendes.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        $('.js_fhchildrendes .js_kuang').eq(Number(arr[i]) - 2).addClass('checkG')
                    }
                }
                uploadParmas.memberBase.fhchildren = data.memberBase.fhchildren;
                uploadParmas.memberBase.fhchildrendes = data.memberBase.fhchildrendes;

                //
                let arr1 = data.memberBase.allergyhistory.split(',');
                uploadParmas.memberBase.allergyhistory = data.memberBase.allergyhistory;
                $('.js_allergyhistory .js_kuang').removeClass('checkG');
                for (var i = 0; i < arr1.length; i++) {
                    $('.js_allergyhistory .js_kuang').eq(Number(arr1[i]) - 1).addClass('checkG');
                }
                $('.js_baolu .js_kuang').removeClass('checkG');
                let baolu = data.memberBase.exposurehistory.split(',');
                for (var i = 0; i < baolu.length; i++) {
                    $('.js_baolu .js_kuang').eq(Number(baolu[i]) - 1).addClass('checkG');
                }
                uploadParmas.memberBase.exposurehistory = data.memberBase.exposurehistory;
                if (data.memberBase.disability != 2) {
                    $('.js_disability .circle').eq(0).removeClass('cb');
                    $('.js_disability .circle').eq(1).addClass('cb');
                    if (data.memberBase.disabilitydescription != '') {
                        let m = data.memberBase.disabilitydescription.split(',')
                        for (var i = 0; i < m.length; i++) {
                            $('.js_disability .duoxuan .js_kuang').eq(Number(m[i]) - 1).addClass('checkG');
                        }
                    }

                }
                uploadParmas.memberBase.disability = data.memberBase.disability;
                if (data.memberBase.smsmoking != 2) {
                    $('.js_smsmoking .circle').removeClass('cb');
                    if (data.memberBase.smsmoking == 1) {
                        $('.js_smsmoking .circle').eq(1).addClass('cb');
                    }
                    if (data.memberBase.smsmoking == 3) {
                        $('.js_smsmoking .circle').eq(2).addClass('cb');
                    }

                    $('.js_smock_start').val(data.memberBase.smstart);

                    if (data.memberBase.smamount == 1) {

                        $('.js_select_options').find("option:contains('偶尔： < 3支/周')").attr("selected", true);
                    } else if (data.memberBase.smamount == 2) {

                        $('.js_select_options').find("option:contains('少量： 1-4支/日')").attr("selected", true);

                    } else if (data.memberBase.smamount == 3) {

                        $('.js_select_options').find("option:contains('经常： ≥5支/日')").attr("selected", true);

                    }
                    $('.js_smock_age').val(data.memberBase.smend);

                }
                uploadParmas.memberBase.smsmoking = data.memberBase.smsmoking;
                uploadParmas.memberBase.smend = data.memberBase.smend;
                uploadParmas.memberBase.smstart = data.memberBase.smstart;
                uploadParmas.memberBase.smamount = data.memberBase.smamount;
                if (data.memberBase.dkdrinking != 2) {
                    $('.js_dkdrinking .circle').removeClass('cb');
                    if (data.memberBase.dkdrinking == 1) {
                        $('.js_dkdrinking .circle').eq(1).addClass('cb');
                    }
                    if (data.memberBase.dkdrinking == 3) {
                        $('.js_dkdrinking .circle').eq(2).addClass('cb');
                    }
                    $('.js_smock_start').val(data.memberBase.smstart);

                    if (data.memberBase.dktype == 1) {

                        $('.js_dirink_dktype').find("option:contains('色酒（酒精含量< 15）')").attr("selected", true);
                    } else if (data.memberBase.dktype == 2) {
                        $('.js_dirink_dktype').find("option:contains('啤酒（酒精含量15-40）')").attr("selected", true);

                    } else if (data.memberBase.dktype == 3) {

                        $('.js_dirink_dktype').find("option:contains('白酒（酒精含量≥45）')").attr("selected", true);

                    }
                    if (data.memberBase.dkamount == 1) {

                        $('.js_dirink_dkamount').find("option:contains('少量： 啤酒 < 250-50ml/次，色酒100-150ml/次')").attr("selected", true);
                    } else if (data.memberBase.dkamount == 2) {

                        $('.js_dirink_dkamount').find("option:contains('中量： 啤酒 <500-2500ml/次，色酒100-150ml/次 ')").attr("selected", true);

                    } else if (data.memberBase.dkamount == 3) {
                        $('.js_dirink_dkamount').find("option:contains('大量： 啤酒 > 2500ml/次，其它酒>250ml/次')").attr("selected", true);

                    }
                    if (data.memberBase.dkrate == 1) {
                        $('.js_dirink_dkrate').find("option:contains('偶尔（每年< 3-4次）')").attr("selected", true);
                    } else if (data.memberBase.dkrate == 2) {

                        $('.js_dirink_dkrate').find("option:contains('少量（每周< 3次）')").attr("selected", true);

                    } else if (data.memberBase.dkrate == 3) {

                        $('.js_dirink_dkrate').find("option:contains('经常（每天喝）')").attr("selected", true);

                    }
                    $('.js_dirink_dkend').val(data.memberBase.dkend);
                }
                uploadParmas.memberBase.dkdrinking = data.memberBase.dkdrinking;
                uploadParmas.memberBase.dkamount = data.memberBase.dkamount;
                uploadParmas.memberBase.dkrate = data.memberBase.dkrate;
                uploadParmas.memberBase.dkend = data.memberBase.dkend;
                uploadParmas.memberBase.dktype = data.memberBase.dktype;

                if (data.memberBase.exexercise != 2) {
                    $('.js_exexercise .circle').removeClass('cb');
                    if (data.memberBase.exexercise == 1) {
                        $('.js_exexercise .circle').eq(1).addClass('cb');
                    }
                    if (data.memberBase.exexercise == 3) {
                        $('.js_exexercise .circle').eq(2).addClass('cb');
                    }
                    $('.js_smock_start').val(data.memberBase.smstart);

                    if (data.memberBase.excycle == 1) {
                        $('.js_excycle').find("option:contains('每天锻炼')").attr("selected", true);

                    } else if (data.memberBase.excycle == 2) {

                        $('.js_excycle').find("option:contains('每周1-2次')").attr("selected", true);

                    } else if (data.memberBase.excycle == 3) {
                        $('.js_excycle').find("option:contains('每周3次及以上')").attr("selected", true);


                    }
                    if (data.memberBase.extime == 1) {
                        $('.js_extime').find("option:contains('< 30分钟')").attr("selected", true);
                    } else if (data.memberBase.extime == 2) {
                        $('.js_extime').find("option:contains('30-60分钟')").attr("selected", true);

                    } else if (data.memberBase.extime == 3) {
                        $('.js_extime').find("option:contains('1小时以上')").attr("selected", true);

                    }
                    if (data.memberBase.extype == 1) {
                        $('.js_extype').find("option:contains('有氧运动（慢跑、气功、极拳、跳舞、散步、游泳、登山等')").attr("selected", true);

                    } else if (data.extype == 2) {

                        $('.js_extype').find("option:contains('无氧运动（速跑、篮球、排球、足球等剧烈运动')").attr("selected", true);

                    } else if (data.extype == 3) {
                        $('.js_extype').find("option:contains('其他')").attr("selected", true);


                    }
                }
                uploadParmas.memberBase.exexercise = data.memberBase.exexercise;
                uploadParmas.memberBase.excycle = data.memberBase.excycle;
                uploadParmas.memberBase.extime = data.memberBase.extime;
                uploadParmas.memberBase.extype = data.memberBase.extype;
                uploadParmas.memberBase.fhtype = data.memberBase.fhtype;
                var type = data.memberBase.fhtype.split(',');
                $('.js_diet .js_kuang').removeClass('checkG')
                for (var i = 0; i < type.length; i++) {
                    $('.js_diet .js_kuang').eq(Number(type[i]) - 1).addClass('checkG')
                }
                uploadParmas.memberBase.fhamount = data.memberBase.fhamount
                $('.js_yinshl').val(data.memberBase.fhamount);
                $('.js_salt .circle').removeClass('cb');
                $('.js_salt .circle').eq(Number(data.memberBase.salt) - 1).addClass('cb');
                // uploadParmas.memberBase.salt = data.memberBase.salt;
                if (data.memberBase.slsituation != 2) {
                    $('.js_sltime .circle').eq(1).addClass('cb');
                    $('.js_sltime .circle').eq(0).removeClass('cb');
                }
                uploadParmas.memberBase.slsituation = data.memberBase.slsituation;
                $('.js_shuimianl').val(data.memberBase.sltime);
                uploadParmas.memberBase.sltime = data.memberBase.sltime;
                uploadParmas.memberBase.sldescription = data.memberBase.sldescription;
                if (data.memberBase.sldescription != '') {
                    var nn = data.memberBase.sldescription.split(',');
                    for (var i = 0; i < nn.length; i++) {
                        $('.js_sltime .js_kuang').eq(Number(nn[i]) - 1).addClass('checkG');
                    }
                }



            }
        })
    },
    bindevent: function (data) {
        // fetch();

        // function fetch() {
        //     util.fetch('api/user/getPersonInfo').then(function (res) {
        //         $('.js_input_name').val(res.data.userName);
        //         $('.js_input_card').val(res.data.idCard);
        //         uploadParmas.member.name = res.data && res.data.userName || '';
        //         uploadParmas.member.idcard = res.data && res.data.idCard || '';
        //     }).fail(function (res) {
        //         alert(res.msg)
        //     })
        // }
        var _this = this;
        // 建档日期
        $('.js_recorddate').change(function () {
            var time = $(this).val();
            uploadParmas.memberBase.recorddate = time;
        })
        $('.js_input_da').on('input propertychange', function () {
            var value = $(this).val();
            var keyname = $(this).data().keyname;
            var form = $(this).data().form;
            var type = $(this).data().type;
            if (form == '0') {
                uploadParmas.member[keyname] = value;
            } else if (form == '1') {
                uploadParmas.memberBase[keyname] = value;
            } else if (form == '2' && keyname == 'indicatorList' && value) {
                var s = {
                    type: type,
                    indicator: value
                }
                uploadParmas.indicatorList[type - 1] = s;
            } else if (form == '2' && keyname == 'indicatorList' && !value) {
                var s = {
                    type: type,
                    indicator: value
                }
                uploadParmas.indicatorList[type - 1] = null;;
            }

        })
        $('.js_shuimianl').on('input propertychange', function () {
            uploadParmas.memberBase.sltime = $(this).val();
        })
        $('.js_yinshl').on('input propertychange', function () {
            uploadParmas.memberBase.fhamount = $(this).val();
        })

        // 圈选
        $('.js_avdio').on('click', '.js_select', function () {
            var index = $(this).data().index;
            var keyword = $(this).data().keyword;
            var illName = $(this).data().illname; // 既往史中病的名称
            var noselect = $(this).data().noselect;
            var ss = $(this).closest('.js_avdio').data() || {};
            var form = ss.form;
            var keyname = ss.keyname;
            var needhide = $(this).closest('.js_needhide');
            $(this).closest('.js_avdio').find('.js_select').removeClass('cb');
            $(this).addClass('cb');
            if (needhide && needhide.length) { // 需要隐藏的条目
                if (noselect == 1) {
                    $(this).closest('.js_needhide').find('.js_tohide').addClass('hide');
                    $(this).closest('.js_needhide').find('.js_kuang').removeClass('checkG')
                } else {
                    $(this).closest('.js_needhide').find('.js_tohide').removeClass('hide');

                }
                // 既往史
                if (keyword == 'historyList') {
                    uploadParmas['historyList'][illName].optiontype = index
                    // 如果隐藏就置空
                    if (noselect) {
                        uploadParmas['historyList'][illName].description = ''
                        uploadParmas['historyList'][illName].occurrencetime = ''
                        $(this).closest('.js_needhide').find('input').val('');
                    }
                } else if (keyword == 'yichuanshi') {
                    uploadParmas.memberBase[illName] = index;
                    if (noselect) {
                        switch (illName) {
                            case 'fhfather':
                                uploadParmas.memberBase['fhfatherdes'] = '';
                                break;
                            case 'fhmother':
                                uploadParmas.memberBase['fhmotherdes'] = '';
                                break;
                            case 'fhbrother':
                                uploadParmas.memberBase['fhbrotherdes'] = '';
                                break;
                            case 'fhchildren':
                                uploadParmas.memberBase['fhchildrendes'] = '';
                                break;
                        }
                    }
                } else if (keyname == 'disability') { // 残疾情况
                    uploadParmas.memberBase[keyname] = index;
                    if (noselect) {
                        uploadParmas.memberBase['disabilitydescription'] = ''
                    }

                } else if (keyname == 'slsituation') { // 睡眠
                    uploadParmas.memberBase['slsituation'] = index;
                    if (noselect) {
                        uploadParmas.memberBase.sldescription = ''
                    }
                } else if (keyname == 'smsmoking') { //吸烟
                    uploadParmas.memberBase['smsmoking'] = index;
                    if (noselect) {
                        uploadParmas.memberBase.smstart = '';
                        uploadParmas.memberBase.smamount = '';
                        $('.js_smock_start').val('');
                        $('.js_smock_age').val('')
                    }
                } else if (keyname == 'dkdrinking') {
                    uploadParmas.memberBase.dkdrinking = index;

                } else if (keyname == 'exexercise') {
                    uploadParmas.memberBase.exexercise = index;
                }

            } else if (form == 1) { // 第一页的内容
                uploadParmas.memberBase[keyname] = index;

            } else if (form && keyname) {
                uploadParmas.memberBase[keyname] = index;
            }
        })
        //新增生活环境
        $('.js_live').on('click', function () {
            var index = $(this).data().index;
            var keyword = $(this).data().keyword;
            uploadParmas.memberBase[keyword] = index;
            $(this).closest('.live-second').find('.js_live .bb').removeClass('colorCircle');
            $(this).find('.bb').addClass('colorCircle');
        })
        $('.js_smock_start').change(function () {
            uploadParmas.memberBase.smstart = $(this).val();
        })
        // 暴露史
        $('.js_baolu .js_kuang').on('click', function () {
            var index = $(this).data().index;
            if (index == 1) {
                $(this).closest('.js_baolu').find('.js_kuang').removeClass('checkG')
            } else {
                $(this).closest('.js_baolu').find('.js_kuang').eq(0).removeClass('checkG')
            }
            $(this).toggleClass('checkG')
            if (index == 0) {
                uploadParmas.memberBase['exposureHistory'] = '1';
            } else {
                var n = [];
                for (var i = 0; i < $(this).closest('.js_baolu').find('.checkG').length; i++) {
                    var s = $(this).closest('.js_baolu').find('.checkG').eq(i).data().index;
                    n.push(s);
                }
                uploadParmas.memberBase['exposureHistory'] = n.join(',')
            }
        })
        $('.js_guomin_input').on('input propertychange', function () {
            if ($(this).val()) {
                uploadParmas.memberBase['allergyName'] = $(this).val()
                $(this).closest('.js_ywguomin').find('.js_kuang').eq(0).removeClass('checkG');
                $(this).closest('.js_ywguomin').find('.js_kuang').eq(4).addClass('checkG');
                var n = [];
                for (var i = 0; i < $(this).closest('.js_ywguomin').find('.checkG').length; i++) {
                    var s = $(this).closest('.js_ywguomin').find('.checkG').eq(i).data().index;
                    n.push(s);
                }
                uploadParmas.memberBase['allergyHistory'] = n.join(',')
            }

        })
        $('.js_ywguomin .js_kuang').on('click', function () {
            var index = $(this).data().index;
            if (index == 1) {
                $(this).closest('.js_ywguomin').find('.js_kuang').removeClass('checkG')
            } else {
                $(this).closest('.js_ywguomin').find('.js_kuang').eq(0).removeClass('checkG')
            }
            $(this).toggleClass('checkG')
            if (index == 1) {
                uploadParmas.memberBase['allergyHistory'] = '2';
                uploadParmas.memberBase['allergydescription'] = '';
                $('.js_guomin_input').val('')
            } else {
                var n = [];
                for (var i = 0; i < $(this).closest('.js_ywguomin').find('.checkG').length; i++) {
                    var s = $(this).closest('.js_ywguomin').find('.checkG').eq(i).data().index;
                    n.push(s);
                }
                uploadParmas.memberBase['allergyHistory'] = n.join(',')
            }
        })

        // 遗传病
        $('.js_yc .js_kuang').on('click', function () {
            $(this).toggleClass('checkG');
            var name = $(this).closest('.js_yc').data().name
            var n = [];
            for (var i = 0; i < $(this).closest('.js_yc').find('.checkG').length; i++) {
                var index = $(this).closest('.js_yc').find('.checkG').eq(i).data().index;
                n.push(index);
            }
            uploadParmas.memberBase[name] = n.join(',');

        })
        // 既往史下的复选框
        $('.js_jw').on('click', function () {
            $(this).toggleClass('checkG');
            var n = [];
            for (var i = 0; i < $(this).closest('.js_needhide').find('.checkG').length; i++) {
                var index = $(this).closest('.js_needhide').find('.checkG').eq(i).data().index;
                n.push(index);
            }
            uploadParmas.historyList[0].description = n.join(',');

        })
        //  既往史下的时间选择
        $('.js_date .js_birthday').change(function () {
            var index = $(this).data().index;
            uploadParmas.historyList[index].occurrencetime = $(this).val();
        })
        //  既往史下的描述
        $(' .js_date .js_d').change(function () {
            var index = $(this).data().index;
            uploadParmas.historyList[index].description = $(this).val();
        })
        // 框选
        $('.js_avdio').on('click', '.js_kuang', function () {
            var index = $(this).data().index;
            var ss = $(this).closest('.js_avdio').data() || {};
            var form = ss.form;
            var keyname = ss.keyname;
            $(this).toggleClass('checkG');
            var all = $(this).closest('.js_avdio').find('.checkG');
            if (all && all.length) {
                var arr = [];
                for (var i = 0; i < all.length; i++) {
                    var index = $(all[i]).data().index;
                    arr.push(index);
                }
                if (form == 1) {
                    uploadParmas.memberBase[keyname] = arr.join(',');
                } else {
                    uploadParmas.memberBase[keyname] = arr.join(',');
                }

            } else {
                uploadParmas.memberBase[keyname] = '';
            }

        })
        // 下一步
        $('.js_jlda_next').on('click', function () {
            var isEmpty = false;
            var base = uploadParmas.memberBase;
            //|| base.recorddate == ''
            if (base.phonenumber == '' || base.workunit == '' || base.contactorname == '' || base.contactorphone == '') {
                isEmpty = true;
            }
            if (isEmpty) {
                alert('请填写完整的信息')
                return;
            }
            $('.js_base_info').addClass('hide');
            $('.js_heath_info').removeClass('hide');
        })
        $('.js_save_btn').on('click', function () {
            var isEmpty = false;
            if (uploadParmas.indicatorList.length != 6) {
                alert('请填写完整的信息')
                return;
            }
            // 身高体重的校验

            for (var i = 0; i < uploadParmas.indicatorList.length; i++) {
                if (!uploadParmas.indicatorList[i]) {
                    isEmpty = true;
                    break;
                }
            }
            if (uploadParmas.memberBase.smsmoking != '2') {
                uploadParmas.memberBase.smamount = $('.js_select_options option:selected').val()
            } else {
                uploadParmas.memberBase.smamount = ''
            }
            if (uploadParmas.memberBase.dkdrinking != '2') {
                uploadParmas.memberBase.dktype = $('.js_dirink_dktype option:selected').val();
                uploadParmas.memberBase.dkrate = $('.js_dirink_dkrate option:selected').val();
                uploadParmas.memberBase.dkamount = $('.js_dirink_dkamount option:selected').val();
                uploadParmas.memberBase.dkend = $('.js_dirink_dkend').val();
            } else {
                uploadParmas.memberBase.dktype = '';
                uploadParmas.memberBase.dkrate = "";
                uploadParmas.memberBase.dkamount = '';
                uploadParmas.memberBase.dkrate = '';
                uploadParmas.memberBase.dkend = '';
            }
            if (uploadParmas.memberBase.exexercise != '2') {
                // excycle: '', //..锻炼情况 否
                // extime: '', //每次锻炼时间 否
                // extype: '', //锻炼类型 否$('#test option:selected').val();
                uploadParmas.memberBase.excycle = $('.js_excycle option:selected').val();
                uploadParmas.memberBase.extime = $('.js_extime option:selected').val();
                uploadParmas.memberBase.extype = $('.js_extype option:selected').val();

            } else {
                uploadParmas.memberBase.excycle = '';
                uploadParmas.memberBase.extime = '';
                uploadParmas.memberBase.extype = '';
            }
            util.fetch('api/medical/dock/uploadArchives', {
                archives: JSON.stringify(uploadParmas),

            }, {
                type: "POST"
            }).then(function (res) {
                alert('提交成功')
                // _this.qiandoctor(util.getParam('medicalid'))
            }).fail(function (res) {
                alert(res.msg)
            })
        })
    },
    qiandoctor: function (medicalid) {
        util.fetch('api/medical/mymedicalInfo', {
            medicalId: medicalid
        }).then(function (res) {
            if (res.data && res.data[0]) {
                var str = template('qinyuedone', {
                    data: res.data[0]
                })
                $('.js_result').html(str).removeClass('hide');
                $('.js_dangan_info').addClass('hide');
            } else {
                alert(res.msg)
            }

        }).fail(function (res) {
            alert(res.msg)
        })
    }
}
createDA.init();
// 建档日期
$('.js_recorddate').kuiDate({
    className: 'js_recorddate',
    isDisabled: "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选 '2' 表示今日之后不可选
});
//   出生日期
$('.js_birthday').kuiDate({
    className: 'js_birthday',
    isDisabled: "2" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选 '2' 表示今日之后不可选
});
//  戒酒
$('.js_dirink_dkend').kuiDate({
    className: 'js_dirink_dkend',
    isDisabled: "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选 '2' 表示今日之后不可选
});
//   吸烟
$('.js_smock_start').kuiDate({
    className: 'js_smock_start',
    isDisabled: "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选 '2' 表示今日之后不可选
});